package com.dfbz.utils;

import com.dfbz.common.Constr;

public class PageUtil {
    /**
     * 根据总页数获取总分页面
     * @param totalCount 总数量
     * @return 总分页面
     */
    public static long getTotalPage(long totalCount){
        return totalCount % Constr.PAGE_SIZE == 0 ? totalCount / Constr.PAGE_SIZE : totalCount / Constr.PAGE_SIZE + 1;

    }

    public static long getStartPage(long currentPage){
        return currentPage % Constr.PAGE_SIZE == 0 ? currentPage - Constr.PAGE_SIZE + 1 : (currentPage - currentPage % Constr.PAGE_SIZE) + 1;
    }
    public static long getEndPage(long currentPage,long totalCount){
        long startPage = getStartPage(currentPage);
        long totalPage = getTotalPage(totalCount);
        long endPage = startPage + Constr.PAGE_COUNT - 1;
        return endPage > totalCount ? totalPage : endPage;
    }
}